package com.app.DB;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Types;


public class Segway {
	
	public Segway() {
		SegwayName = SegwayTimeUse = SegwayStatus = "";
	 }	
    public Segway(
            String OID,
            String UsrOpt,
            String IsActive,
            String IsDeleted,
            String SegwayName,
            String SegwayTimeUse,
            String SegwayStatus
            
            )
    
   {
        this.OID 					= OID;
        this.UsrOpt 				= UsrOpt;
        this.IsActive 				= IsActive;
        this.IsDeleted 				= IsDeleted;
        this.SegwayName 			= SegwayName;
        this.SegwayTimeUse 			= SegwayTimeUse;
        this.SegwayStatus 			= SegwayStatus;

    }
    //-------------------- Variable -------------------------
    private String OID,
    		UsrOpt,
    		IsActive,
    		IsDeleted,
    		SegwayName,
    		SegwayTimeUse,
    		SegwayStatus;
            
    
    Connect con = new Connect(); 
    Connection conn = con.Connect();
    ResultSet rs = null;
   

    // -------------------- GET-SET -------------------------
    
 
	public String getOID() {
		return OID;
	}
	
	public String getSegwayName() {
		return SegwayName;
	}
	public void setSegwayName(String segwayName) {
		SegwayName = segwayName;
	}
	public String getSegwayTimeUse() {
		return SegwayTimeUse;
	}
	public void setSegwayTimeUse(String segwayTimeUse) {
		SegwayTimeUse = segwayTimeUse;
	}
	public String getSegwayStatus() {
		return SegwayStatus;
	}
	public void setSegwayStatus(String segwayStatus) {
		SegwayStatus = segwayStatus;
	}
	public void setOID(String oID) {
		OID = oID;
	}
	public String getUsrOpt() {
		return UsrOpt;
	}
	public void setUsrOpt(String usrOpt) {
		UsrOpt = usrOpt;
	}
	public String getIsActive() {
		return IsActive;
	}
	public void setIsActive(String isActive) {
		IsActive = isActive;
	}
	public String getIsDeleted() {
		return IsDeleted;
	}
	public void setIsDeleted(String isDeleted) {
		IsDeleted = isDeleted;
	}
	
	//-------------------- SQL ------------------------
    public ResultSet selectSegway(String StrSegwayName) throws Exception {
        String StrSql = "SELECT [OID],"
                + "[LastModified],"
                + "[ModifiedDate],"
                + "[ModifiedTime],"
                + "[ModifiedBy],"
                + "[UserModified],"
                + "[CreatDate],"
                + "[CreatTime],"
                + "[CreatedBy],"
                + "[UserCreate],"
                + "[IsActive],"
                + "[IsDeleted],"
                
                + "[SegwayName],"
                + "[SegwayTimeUse],"
                + "[SegwayStatus] "
                
  				+ "FROM [MegaAutoCare].[dbo].[udfSegway]() "
  
                + "WHERE [IsDeleted]='0' "; 

        
        if (!StrSegwayName.equals("")) {
            StrSql += " AND [SegwayName] LIKE '" + StrSegwayName + "' ";
        }

        //return sqlsel.getReSultSQL(StrSql);
        return con.selectData(StrSql);
    }

   

    public String OperationData(String OperationType) throws Exception {
        try {
        		conn = con.Connect();
                java.sql.CallableStatement cstmt = conn.prepareCall("{call stpSegwayManagement(?,?,?,?,? ,?,?,?,?)}");
                
                cstmt.setString(1, OperationType);
                cstmt.setString(2, getOID());
                cstmt.setString(3, getUsrOpt());
                cstmt.setString(4, getIsActive());
                cstmt.setString(5, getIsDeleted());

                cstmt.setString(6, getSegwayName());
                cstmt.setString(7, getSegwayTimeUse());
                cstmt.setString(8, getSegwayStatus());
                
                cstmt.registerOutParameter(9, Types.VARCHAR);
                cstmt.execute();
                return cstmt.getString(9);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (conn != null) {
                conn.close();
            }
        }
        return null;
    }
}
